<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <title>Title</title>
</head>
<body>
<form class="layui-form" lay-filter="userForm" id="add_user_form" action="" style="padding:15px 10px;">
    <input type="hidden" name="userid">
    <div class="layui-form-item">
        <label class="layui-form-label">登录名：</label>
        <div class="layui-input-block">
            <input type="text" name="loginname" required  lay-verify="required" placeholder="建议是英文" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">姓名：</label>
        <div class="layui-input-block">
            <input type="text" name="username" required  lay-verify="required" placeholder="请输入姓名" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">密码：</label>
        <div class="layui-input-block">
            <input type="password" name="password" required  lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">用户角色：</label>
        <div class="layui-input-block" >
            <select name="roleid" id="roles_add"  xm-select-radio=""  xm-select-search="" xm-select="roles2" xm-select-direction="down">
                <option value="-1">请选择</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">邮箱：</label>
        <div class="layui-input-block">
            <input type="text" name="oemail"  placeholder="请输入邮箱" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">性别：</label>
        <div class="layui-input-block">
            <input type="radio" name="gender" value="1" title="男">
            <input type="radio" name="gender" value="2" title="女" checked>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">出生日期：</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input" name="birthdate" placeholder="yyyy-MM-dd" id="birthdate">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">头像：</label>
        <div class="layui-input-block">
            <img src="" id="showtouxiang" style="width: 100px;height:100px;border-radius: 50%" alt="">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">上传头像：</label>
        <input type="hidden" name="touxiang" id="touxiaing">
        <div class="layui-input-block">
            <button type="button" class="layui-btn" id="upload">
                <i class="layui-icon">&#xe67c;</i>上传图片
            </button>
            <%--<div class="layui-upload-list">--%>
                <%--<img class="layui-upload-img" id="demo1" style="width: 100%;height: 100%">--%>
                <%--<p id="demoText"></p>--%>
            <%--</div>--%>
        </div>
    </div>



    <script>

       setTimeout(function () {
           $("#showtouxiang").attr("src","${path}/"+$("#touxiaing").val());
       },500)


        layui.form.render();
        $.get("${path}/role/search",function(data){
            $.each(data,function(){
                var opt = $("<option></option>").appendTo("#roles_add");
                opt.text(this.rolelabel).val(this.roleid);
            });
            layui.form.render()
        });

        //时间选择器
        layui.laydate.render({
            elem: '#birthdate' //指定元素
        });


        var upload = layui.upload;

        //执行实例
        var uploadInst = upload.render({
            elem: '#upload' //绑定元素
            ,accept: 'file'
            ,url: '${path}/user/touxiangadd' //上传接口
            ,done: function(res, index, upload){
                console.log();
                //上传完毕回调
                $('#showtouxiang').attr('src', "${path}/"+res.imgPath); //显示图片链接（base64）
                $("#touxiaing").val(res.imgPath);//文件隐藏域
            }
            ,error: function(){
                //请求异常回调
            },before: function(obj){
                console.log(obj)
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){

                });
            }

        });

    </script>
</form>
</body>
</html>
